<template>

</template>

<script>
export default {
  name: 'CartUtil',
  data: function () {
    return {
      callback: false,
      params: {}
    }
  },
  mounted () {
    let $this = this
    $this.params = {}
    $this.callback = false
    $this.bus.$on('CartUtilCallBus', function (type, params, callback) {
      $this.params = params
      $this.callback = callback
      if (type==='setCartProductItem'){
        $this.setCartProductItem()
      }
      if (type==='deleteCartShopItem'){
        $this.deleteCartShopItem()
      }
      if (type==='deleteCartProductStockItem'){
        $this.deleteCartProductStockItem()
      }
    })
  },
  methods: {
    // 设置-单个商品-数量
    setCartProductItem: function () {
      let $this = this
      $this.loading = true
      $this.MyRequest($this.ApiDoNameMember + 'Member/setCartProductItem', {
        shopProductStockId: $this.params.id,
        nums: $this.params.nums,
      }, function (data) {
        $this.loading = false
        if (typeof $this.callback === 'function') {
          $this.callback()
        }
        $this.$forceUpdate()
      }, function (msg) {
        $this.loading = false
        $this.$message.error(msg)
      })
    },
    // 删除-单个店铺
    deleteCartShopItem: function () {
      let $this = this
      $this.loading = true
      $this.MyRequest($this.ApiDoNameMember + 'Member/deleteCartShopItem', {
        shopId: $this.params.shopId,
      }, function (data) {
        $this.loading = false
        if (typeof $this.callback === 'function') {
          $this.callback()
        }
        $this.$forceUpdate()
      }, function (msg) {
        $this.loading = false
        $this.$message.error(msg)
      })
    },
    // 删除-单个型号
    deleteCartProductStockItem: function () {
      let $this = this
      $this.loading = true
      $this.MyRequest($this.ApiDoNameMember + 'Member/deleteCartProductStockItem', {
        shopProductStockId: $this.params.id,
      }, function (data) {
        $this.loading = false
        if (typeof $this.callback === 'function') {
          $this.callback()
        }
        $this.$forceUpdate()
      }, function (msg) {
        $this.loading = false
        $this.$message.error(msg)
      })
    },
  }
}
</script>

<style scoped>

</style>
